package com.dwxt.cdms.controller;

import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.entity.HeartVoice;
import com.dwxt.cdms.service.HeartVoiceService;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.PartyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;



/*
 * @Author liuhongfei
 * @Description 心之声设备关联
 * @Date 10:55 2020/9/8
 */

@RestController
@RequestMapping("/cdms/heartVoice")
public class HeartVoiceController {

    @Autowired
    private HeartVoiceService heartVoiceService;


    /*
     * @Author liuhongfei
     * @Description 心之声数据采集
     * @Date 14:47 2020/9/5
     * @Param
     * @return
     */
    @RequestMapping("/data")
    public BaseResult insertData(HttpServletRequest request,
                                 HttpServletResponse response, HeartVoice heartVoice)
            throws IOException {
        return heartVoiceService.insertData(heartVoice);
    }

    /*
     * @Author liuhongfei
     * @Description 心之声个人数据获取
     * @Date 14:46 2020/9/5
     * @Param
     * @return
     */
    @RequestMapping("/selectPersonData")
    public BaseResult selectPersonData(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        String currentUserId = PartyUtil.getCurrentUserId();
        return BaseResult.ok(heartVoiceService.selectPersonData(pageNum, pageSize, currentUserId));
    }

    /*
     * @Author liuhongfei
     * @Description 心电数据列表
     * @Date 10:53 2020/9/8
     * @Param
     * @return
     */
    @RequestMapping("/selectDataList")
    public BaseResult selectDataList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return BaseResult.ok(heartVoiceService.selectPersonData(pageNum, pageSize, null));
    }

    /**
     * 查询某个客户的心电分页
     * @param page
     * @param customerId
     * @return
     */
    @RequestMapping("/selectSmallPersonData")
    public BaseResult selectSmallPersonData(Page page, Integer customerId) {
        return heartVoiceService.selectSmallPersonData(page, customerId);
    }

}
